<template>
  <div class="layout">
    <Header />
    <el-container v-if="state.showMenu" class="container">
      <el-aside class="aside">
        <Nav />
      </el-aside>
      <el-container class="content">
        <div class="main">
          <router-view />
        </div>
        <!-- <Footer /> -->
      </el-container>
    </el-container>
    <el-container v-else class="container">
      <router-view />
    </el-container>
  </div>
</template>

<script>
import { onMounted, onUnmounted, reactive } from 'vue'
import Header from '@/components/Header.vue'
// import Footer from '@/components/Footer.vue'
import Nav from '@/components/nav.vue'
import { useRouter, useRoute } from 'vue-router'
import { pathMap, localGet } from '@/utils'
import { useStore } from "vuex";
export default {
  name: 'App',
  components: {
    Header,
    // Footer,
    Nav
  },
  setup() {
    const router = useRouter()
    const route = useRoute()
    const store = useStore();
    const state = reactive({
      defaultOpen: [],
      showMenu: true,
      currentPath: '/dashboard',
      count: {
        number: 1
      }
    })
    onMounted(() => {
      windowback()
    })
    const goBack = ()=> {
      history.pushState(null, null, document.URL);
    }
    const onUnmounted = ()=> {
      window.removeEventListener('popstate', this.goBack, false);
    }
    const windowback = ()=> {
      // 监听浏览器原生回退事件
      if (!localGet("AuthButtons")) {
        store.dispatch("cart/getAuthButton");
      } else {
        store.commit("cart/getAuthButtons");
      }
      if (window.history && window.history.pushState) {
        history.pushState(null, null, document.URL);
        window.addEventListener('popstate', () => {
          if (!localGet('userinfo').token) {
            state.showMenu = false
          }
        }, false);
      }
    }
    return {
      state,
      windowback,
      goBack,
      onUnmounted
    }
  }
}
</script>

<style scoped>
  .layout {
    min-height: 100vh;
    background-color: #ffffff;
  }
  .container {
    /* height: 100vh - 51px; */
    height: calc(100vh - 51px)
  }
  .aside {
    width: 200px!important;
    /* background-color: #222832; */
    overflow: hidden;
    overflow-y: auto;
    -ms-overflow-style: none;
    overflow: -moz-scrollbars-none;
  }
  .aside::-webkit-scrollbar {
    display: none;
  }
  .head {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
  }
  .head > div {
    display: flex;
    align-items: center;
  }

  .head img {
    width: 50px;
    height: 50px;
    margin-right: 10px;
  }
  .head span {
    font-size: 20px;
    color: #ffffff;
  }
  .line {
    border-top: 1px solid hsla(0,0%,100%,.05);
    border-bottom: 1px solid rgba(0,0,0,.2);
  }
  .content {
    display: flex;
    flex-direction: column;
    max-height: 100vh;
    overflow: hidden;
  }
  .main {
    height: calc(100vh - 100px);
    padding: 10px;
    overflow: auto;
  }
</style>
<style>
  body {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }
  .el-menu {
    border-right: none!important;
  }
  .el-submenu {
    /* border-top: 1px solid hsla(0, 0%, 100%, .05); */
    /* border-bottom: 1px solid rgba(0, 0, 0, .2); */
  }
  .el-submenu:first-child {
    border-top: none;
  }
  .el-submenu [class^="el-icon-"] {
    vertical-align: -1px!important;
  }
  a {
    color: #409eff;
    text-decoration: none;
  }
  .el-pagination {
    text-align: center;
    margin-top: 20px;
  }
  .el-popper__arrow {
    display: none;
  }
  .el-menu-item-group__title {
    display: none;
  }
  .el-submenu__title {
    height: 40px;
    line-height: 40px;
  }
</style>
